******************************************Do file for******************************************
****************Beyer, Audun, Carl Henrik Knutsen and Bjørn Erik Rasch (2014)****************** 
*Election Campaigns, Issue Focus and Voting Intentions: Survey Experiments of Norwegian Voters* 
****************************Scandinavian Political Studies*************************************
***********************************************************************************************


***All analysis in this do file pertains to the web-based survey*******************************
*clear
*use "M:\www_docs\Data\BKR_SPS.dta", clear


**Providing proper variable names to the data (which were imported from excel file provided by the polling firm)
rename var11 byland
rename var12 fylke
rename var13 landsdel
rename var14 party
rename var9 incomehh
rename var10 education
rename var8 age
rename var7 gender
rename var15 taxpol
rename var16 healthsocpol
rename var17 elderlypol
rename var18 environmpol
rename var19 transportpol
rename var20 defensepol
rename var21 educationpol
rename var22 familypol
rename var23 foreignpol
rename var24 immigrpol
rename var25 otherpol
rename var26 uncertainpol
rename var27 pielectionoutcome
rename var28 piinterperscom
rename var29 pk1
rename var30 pk2
rename var31 pk3
rename var32 pigen
rename var33 prinfluencepol
rename var34 prpolcomplic
rename var35 prvotematters
rename var36 mionlinepaper
rename var37 minatnewspaper
rename var38 mireglocal
rename var39 mitelev
rename var40 miradio
rename var41 miweb
rename var42 mihowoftendebate
rename var43 minrk
rename var44 mitv2
rename var45 Ttaxpol
rename var46 Thealthsocpol
rename var47 Telderlypol
rename var48 Tenvironmpol
rename var49 Ttransportpol
rename var50 Tdefensepol
rename var51 Teducationpol
rename var52 Tfamilypol
rename var53 Tforeignpol
rename var54 Timmigrpol
rename var55 Totherpol
rename var56 Tuncertainpol
rename var57 aspectenvir
rename var58 aspecttax
rename var59 aspecthealth
rename var60 aspectelderly
rename var61 aspectimmigr
rename var62 fcgamevsissue
rename var63 fcattentionvsproblems
rename var64 fcelectedvsproblems
rename var65 cyndiffissues
rename var66 cynadvisors
rename var67 cynrealchoice
rename var68 cynrealdiscussion
rename var69 subsample

***generating party dummies for baseline question
generate DNA = 1 if party==1
generate FRP = 1 if party==2
generate H = 1 if party==3
generate KP = 1 if party==4
generate R = 1 if party==5
generate SP = 1 if party==6
generate SV = 1 if party==7
generate V = 1 if party==8
generate Other = 1 if party==9
generate Uncertain = 1 if party==10
generate Unanswered = 1 if party==11
generate Novote = 1 if party==12
generate Cannotvote = 1 if party==13

mvencode DNA FRP H KP R SP SV V Other Uncertain Unanswered Novote Cannotvote, mv(0) override

rename var70 partyim
rename var71 partyen

***generating party dummies for immigration-question
generate DNAi = 1 if partyim==1
generate FRPi = 1 if partyim==2
generate Hi = 1 if partyim==3
generate KPi = 1 if partyim==4
generate Ri = 1 if partyim==5
generate SPi = 1 if partyim==6
generate SVi = 1 if partyim==7
generate Vi = 1 if partyim==8
generate Otheri = 1 if partyim==9
generate Uncertaini = 1 if partyim==10
generate Unansweredi = 1 if partyim==11
generate Novotei = 1 if partyim==12
generate Cannotvotei = 1 if partyim==13

***generating party dummies for environment
generate DNAe = 1 if partyen==1
generate FRPe = 1 if partyen==2
generate He = 1 if partyen==3
generate KPe = 1 if partyen==4
generate Re = 1 if partyen==5
generate SPe = 1 if partyen==6
generate SVe = 1 if partyen==7
generate Ve = 1 if partyen==8
generate Othere = 1 if partyen==9
generate Uncertaine = 1 if partyen==10
generate Unanswerede = 1 if partyen==11
generate Novotee = 1 if partyen==12
generate Cannotvotee = 1 if partyen==13

mvencode Cannotvotee Novotee Unanswerede Uncertaine Othere Ve SVe SPe Re KPe DNAe FRPe He if partyen!=., mv(0) override
mvencode Cannotvotei Novotei Unansweredi Uncertaini Otheri Vi SVi SPi Ri KPi DNAi FRPi Hi if partyim!=., mv(0) override

**generating dummies measuring post-treatment party change for immigration sample
generate DNAic = DNAi - DNA
generate FRPic = FRPi - FRP
generate Hic = Hi-H
generate KPic=KPi-KP
generate Ric=Ri-R
generate SPic=SPi-SP
generate SVic=SVi-SV
generate Vic=Vi-V
generate Otheric=Otheri-Other
generate Uncertainic=Uncertaini-Uncertain
generate Unansweredic=Unansweredi-Unanswered
generate Novoteic=Novotei-Novote
generate Cannotvoteic=Cannotvotei-Cannotvote

**generating dummies measuring post-treatment party change for environment sample
generate DNAec = DNAe - DNA
generate FRPec = FRPe - FRP
generate Hec = He-H
generate KPec=KPe-KP
generate Rec=Re-R
generate SPec=SPe-SP
generate SVec=SVe-SV
generate Vec=Ve-V
generate Otherec=Othere-Other
generate Uncertainec=Uncertaine-Uncertain
generate Unansweredec=Unanswerede-Unanswered
generate Novoteec=Novotee-Novote
generate Cannotvoteec=Cannotvotee-Cannotvote

**Investigating the changes
histogram Hic, discrete frequency
(start=-1, width=1)
histogram Hic if H==1, discrete frequency
(start=-1, width=1)
histogram DNAic if DNA==1, discrete frequency
(start=-1, width=1)
histogram FRPic if FRP==1, discrete frequency
(start=-1, width=1)
histogram SVic if SV==1, discrete frequency
(start=-1, width=1)
histogram SVec if SV==1, discrete frequency
(start=-1, width=1)
histogram DNAec if DNA==1, discrete frequency
(start=-1, width=1)
histogram DNAec if DNA==0, discrete frequency
(start=0, width=1)
histogram SVec if SV==0, discrete frequency
(start=0, width=1)

**generating absolute value change variables for each party (both to and from party)
*immigration 
generate aDNAic = abs(DNAic)
generate aFRPic = abs(FRPic)
generate aHic = abs(Hic)
generate aKPic=abs(KPic)
generate aRic=abs(Ric)
generate aSPic=abs(SPic)
generate aSVic=abs(SVic)
generate aVic=abs(Vic)
generate aOtheric=abs(Otheric)
generate aUncertainic=abs(Uncertainic)
generate aUnansweredic=abs(Unansweredic)
generate aNovoteic=abs(Novoteic)
generate aCannotvoteic=abs(Cannotvoteic)
*environment
generate aDNAec = abs(DNAec)
generate aFRPec = abs(FRPec)
generate aHec = abs(Hec)
generate aKPec=abs(KPec)
generate aRec=abs(Rec)
generate aSPec=abs(SPec)
generate aSVec=abs(SVec)
generate aVec=abs(Vec)
generate aOtherec=abs(Otherec)
generate aUncertainec=abs(Uncertainec)
generate aUnansweredec=abs(Unansweredec)
generate aNovoteec=abs(Novoteec)
generate aCannotvoteec=abs(Cannotvoteec)

*generating change variable(for all party changes)
generate aimchange = (aDNAic + aFRPic + aHic+aKPic+aRic+aSPic+aSVic+aVic+aOtheric+aUncertainic+aUnansweredic+aNovoteic+aCannotvoteic)/2
generate aenchange = (aDNAec + aFRPec + aHec+aKPec+aRec+aSPec+aSVec+aVec+aOtherec+aUncertainec+aUnansweredec+aNovoteec+aCannotvoteec)/2

*generating political knowledge indices
generate addkun = kunnskap1+kunnskap2+kunnskap3
generate medkun = 1 if addkun >0 & addkun<4
mvencode medkun if addkun==0, mv(0) override
generate hoeykun = 1 if addkun>1 & addkun<4
mvencode hoeykun if addkun==0|addkun==1, mv(0) override

**generating cynicism indices
generate FCcynicism = ((3-fcgamevsissue)+fcattentionvsproblems+fcelectedvsproblems)/3
generate cynicismfive= (cyndiffissues +cynadvisors +(6-cynrealchoice) +(6-cynrealdiscussion))/4

*generating dummies capturing change to issue ownership parties for different sub-samples
generate toFRPi =1 if FRPic==1
generate toVSVe=1 if Vec==1|SVec==1

mvencode toFRPi if partyim!=., mv(0) override
mvencode toVSVe if partyen!=., mv(0) override


**Table 1 in the paper

logit aimchange age gender education pigen addkun cynicismfive immigrpol
estimates store rra
logit aimchange age gender education pigen addkun cynicismfive immigrpol DNA FRP H SP SV V R  Other
estimates store rrb
logit toFRPi age gender education pigen addkun cynicismfive immigrpol if FRP==0
estimates store rrc

logit aenchange age gender education pigen addkun cynicismfive environmpol
estimates store rrd
logit aenchange age gender education pigen addkun cynicismfive environmpol DNA FRP H SP SV V R  Other
estimates store rre
logit toVSVe age gender education pigen addkun cynicismfive environmpol if (V==0 & SV==0)
estimates store rrf

estout rra rrb rrc rrd rre rrf, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N) style(fixed)

**Table A3

logit aimchange age gender education
estimates store a
logit aimchange age gender education pigen
estimates store b
logit aimchange age gender education addkun
estimates store c
logit aimchange age gender education cynicismfive
estimates store d
logit aimchange age gender education immigrpol
estimates store e
logit aimchange age gender education pigen addkun cynicismfive immigrpol
estimates store f

estout  a b c d e, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N) style(fixed)

**Table A4

logit toFRPi age gender education if FRP==0
estimates store a
logit toFRPi age gender education pigen if FRP==0
estimates store b
logit toFRPi age gender education addkun if FRP==0
estimates store c
logit toFRPi age gender education cynicismfive if FRP==0
estimates store d
logit toFRPi age gender education immigrpol if FRP==0
estimates store e
logit toFRPi age gender education pigen addkun cynicismfive immigrpol if FRP==0
estimates store f

estout  a b c d e f, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N)style(fixed)

**Table A5

logit aenchange age gender education
estimates store a
logit aenchange age gender education pigen
estimates store b
logit aenchange age gender education addkun
estimates store c
logit aenchange age gender education cynicismfive
estimates store d
logit aenchange age gender education environmpol
estimates store e
logit aenchange age gender education pigen addkun cynicismfive environmpol
estimates store f

estout  a b c d e, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N) style(fixed)

***Table A6
logit toVSVe age gender education if (V==0 & SV==0)
estimates store a
logit toVSVe age gender education pigen if (V==0 & SV==0)
estimates store b
logit toVSVe age gender education addkun if (V==0 & SV==0)
estimates store c
logit toVSVe age gender education cynicismfive if (V==0 & SV==0)
estimates store d
logit toVSVe age gender education environmpol if (V==0 & SV==0)
estimates store e
logit toVSVe age gender education pigen addkun cynicismfive environmpol if (V==0 & SV==0)
estimates store f

estout  a b c d e f, cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) starlevels (* 0.10 ** 0.05 *** 0.01) stats (N) style(fixed)

***Checking for multi-collinearity
correlate age gender education pigen addkun cynicismfive immigrpol if _est_rra==1
correlate age gender education pigen addkun cynicismfive environmpol if _est_rrd==1

regress aimchange age gender education pigen addkun cynicismfive immigrpol
estat vif

regress aenchange age gender education pigen addkun cynicismfive environmpol
estat vif

***********Simulation exercise for evaluating the uncertainty related to the net changes for the different parties (Figure 4)
***Generating 95 Confidence Intervals for immigration treatment

capture drop Effect Upper Lower Index
gen Index = _n
gen Effect = .
gen Upper = .
gen Lower = .

capture drop change_*
forvalues i = 1(1)9 {
    gen change_to_`i' = (party != `i' & partyim == `i')
    gen change_from_`i' = (party == `i' & partyim != `i')
    replace change_to_`i' = . if partyim == .
    replace change_from_`i' = . if partyim == .
    capture drop _B*
    capture estsimp reg change_to_`i', genname(_BT)
    if _rc!=0 {
        gen _BT1 = 0
    }
    capture estsimp reg change_from_`i', genname(_BF)
    if _rc!=0 {
        gen _BF1 = 0
    }
    capture gen _B = _BT1 - _BF1
    _pctile _B, p(2.5, 50, 97.5)
    replace Lower = r(r1) if party == `i'
    replace Effect = r(r2) if party == `i'
    replace Upper = r(r3) if party == `i'  
}

by party, sort: summarize Lower Effect Upper

***Generating 95% intervals for environment treatment

capture drop Effect Upper Lower Index
gen Index = _n
gen Effect = .
gen Upper = .
gen Lower = .

capture drop change_*
forvalues i = 1(1)9 {
    gen change_to_`i' = (party != `i' & partyen == `i')
    gen change_from_`i' = (party == `i' & partyen != `i')
    replace change_to_`i' = . if partyen == .
    replace change_from_`i' = . if partyen == .
    capture drop _B*
    capture estsimp reg change_to_`i', genname(_BT)
    if _rc!=0 {
        gen _BT1 = 0
    }
    capture estsimp reg change_from_`i', genname(_BF)
    if _rc!=0 {
        gen _BF1 = 0
    }
    capture gen _B = _BT1 - _BF1
    _pctile _B, p(2.5, 50, 97.5)
    replace Lower = r(r1) if party == `i'
    replace Effect = r(r2) if party == `i'
    replace Upper = r(r3) if party == `i'  
}

by party, sort: summarize Lower Effect Upper